// license-header java merge-point
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 */
package fr.upstlse.glre.business.domain;
/**
 * @see fr.upstlse.glre.business.domain.Stage
 */
public class StageDaoImpl
    extends fr.upstlse.glre.business.domain.StageDaoBase
{
    /**
     * @see fr.upstlse.glre.business.domain.StageDao#toStageVO(fr.upstlse.glre.business.domain.Stage, fr.upstlse.glre.business.vo.StageVO)
     */
    public void toStageVO(
        fr.upstlse.glre.business.domain.Stage source,
        fr.upstlse.glre.business.vo.StageVO target)
    {
        super.toStageVO(source, target);
        if(source != null) {
        	target.setEntrepriseVO(getEntrepriseDao().toEntrepriseVO(source.getEntreprise()));
            target.setProfesseurVO(getProfesseurDao().toProfesseurVO(source.getProfesseur()));
        }
    }


    /**
     * @see fr.upstlse.glre.business.domain.StageDao#toStageVO(fr.upstlse.glre.business.domain.Stage)
     */
    public fr.upstlse.glre.business.vo.StageVO toStageVO(final fr.upstlse.glre.business.domain.Stage entity)
    {
        // @todo verify behavior of toStageVO
        return super.toStageVO(entity);
    }


    /**
     * Retrieves the entity object that is associated with the specified value object
     * from the object store. If no such entity object exists in the object store,
     * a new, blank entity is created
     */
    private fr.upstlse.glre.business.domain.Stage loadStageFromStageVO(fr.upstlse.glre.business.vo.StageVO stageVO)
    {
    	if(stageVO != null) {
    		fr.upstlse.glre.business.domain.Stage stage = this.load(stageVO.getId());
            if (stage == null)
            {
                stage = fr.upstlse.glre.business.domain.Stage.Factory.newInstance();
            }
            return stage;
    	}
    	else  {
            return null;
        }
    }

    
    /**
     * @see fr.upstlse.glre.business.domain.StageDao#stageVOToEntity(fr.upstlse.glre.business.vo.StageVO)
     */
    public fr.upstlse.glre.business.domain.Stage stageVOToEntity(fr.upstlse.glre.business.vo.StageVO stageVO)
    {
        fr.upstlse.glre.business.domain.Stage entity = this.loadStageFromStageVO(stageVO);
        if(entity != null) {
        	this.stageVOToEntity(stageVO, entity, true);
        }
        
        return entity;
        	
        
    }


    /**
     * @see fr.upstlse.glre.business.domain.StageDao#stageVOToEntity(fr.upstlse.glre.business.vo.StageVO, fr.upstlse.glre.business.domain.Stage)
     */
    public void stageVOToEntity(
        fr.upstlse.glre.business.vo.StageVO source,
        fr.upstlse.glre.business.domain.Stage target,
        boolean copyIfNull)
    {
        super.stageVOToEntity(source, target, copyIfNull);
        if(copyIfNull || source.getEntrepriseVO() != null)
        {
        	target.setEntreprise(getEntrepriseDao().entrepriseVOToEntity(source.getEntrepriseVO()));
        }
        
        if(copyIfNull || source.getProfesseurVO() != null)
        {
        	target.setProfesseur(getProfesseurDao().professeurVOToEntity(source.getProfesseurVO()));
        }
    }


	@Override
	public Object create(int transform, Stage stage) {
		if (stage == null)
        {
            throw new IllegalArgumentException(
                "Stage.create - 'stage' can not be null");
        }
		
		getEntrepriseDao().create(stage.getEntreprise());
		getProfesseurDao().create(stage.getProfesseur());
        this.getHibernateTemplate().save(stage);
        return this.transformEntity(transform, stage);
	}


	@Override
	public void update(Stage stage) {
		if (stage == null)
        {
            throw new IllegalArgumentException(
                "Stage.update - 'stage' can not be null");
        }
		getEntrepriseDao().update(stage.getEntreprise());
		getProfesseurDao().update(stage.getProfesseur());
        this.getHibernateTemplate().update(stage);
	}
	
	
	
    
    

}